namespace Collaboris.Saf.Actions.Wss.Tests.Generated
{
    using Engine.Report;

    using Microsoft.SharePoint;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Saf.Tests;
    using Entities;

    using Sharepoint.WSS.ContentTypes;

    using SharePoint.Wss.Lists;
    using SharePoint.Wss.Webs;

    using Wss.ContentType;

    [TestClass]
    public class SynchroniseContentTypesTest
    {

        [TestMethod]
        public void SynchroniseContentTypes_Test()
        {
            WSSTestAssistant<SynchroniseContentTypes, ContentTypeInfo> synchronisecontenttypes =
                    new WSSTestAssistant<SynchroniseContentTypes, ContentTypeInfo>(TestEnvironment.PublishingSite, 
                        "SynchroniseContentTypesTestWeb", "BLANKINTERNET#0");

            using (synchronisecontenttypes)
            {
                SPWeb newWeb = SPWebHelper.CreateWeb(
                     synchronisecontenttypes.TestWeb,
                     true,
                     "Whatever",
                     "Whatever again",
                     "BLANKINTERNET#0",
                     "new",
                     1033,
                     false,
                     false);

                SPList pages = SPListHelper.GetList(newWeb, "Pages");

                // lets delete a field, that should be added back by the action!
                pages.ContentTypes["Article Page"].FieldLinks.Delete("Description");
                pages.Update();
                Assert.IsNull(pages.ContentTypes["Article Page"].FieldLinks["Description"]);

                MacroReport doReport = synchronisecontenttypes.DoMacro();

                pages = SPListHelper.GetList(newWeb, "Pages");

                Assert.IsTrue(SPContentTypeHelper.IsContentTypeAssociated(pages, synchronisecontenttypes.FirstEntity.ContentTypeName));

                Assert.IsNotNull(SPListHelper.GetList(newWeb, "Pages").ContentTypes["Article Page"].FieldLinks["Description"]);
                
        
            }
        }

        // tests just the report mode
        [TestMethod]
        public void SynchroniseContentTypes_Report_Only_Mode_Test()
        {
            WSSTestAssistant<SynchroniseContentTypes, ContentTypeInfo> synchronisecontenttypes =
                    new WSSTestAssistant<SynchroniseContentTypes, ContentTypeInfo>(TestEnvironment.PublishingSite,
                        "SynchroniseContentTypesTestWeb", "BLANKINTERNET#0");

            using (synchronisecontenttypes)
            {
                if (System.IO.File.Exists(synchronisecontenttypes.FirstEntity.ReportFileName))
                    System.IO.File.Delete(synchronisecontenttypes.FirstEntity.ReportFileName);

                synchronisecontenttypes.FirstEntity.ReportOnlyMode = true;
                MacroReport doReport = synchronisecontenttypes.DoMacro();

                Assert.IsTrue(System.IO.File.Exists(synchronisecontenttypes.FirstEntity.ReportFileName));

            }
        }

    }
}
